package com.fqxiny.lease.web.admin.schedule;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.fqxiny.lease.model.entity.LeaseAgreement;
import com.fqxiny.lease.model.enums.LeaseStatus;
import com.fqxiny.lease.web.admin.service.LeaseAgreementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author : 戚欣扬
 * @code : 定时任务
 */
@Component
public class ScheduleTasks {
    @Autowired
    LeaseAgreementService leaseAgreementService;

    @Scheduled(cron = "0 0 0 * * ?")
    public void dailyUpdateLeaseAgreement(){
        //将 截止日期小于当前时间 以及 状态为6,7租约状态修改未已到期
        LambdaUpdateWrapper<LeaseAgreement> leaseAgreementLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        leaseAgreementLambdaUpdateWrapper.lt(LeaseAgreement::getLeaseEndDate,new Date());
        leaseAgreementLambdaUpdateWrapper.in(LeaseAgreement::getStatus, LeaseStatus.RENEWING,LeaseStatus.WITHDRAWN);
        leaseAgreementLambdaUpdateWrapper.set(LeaseAgreement::getStatus,LeaseStatus.EXPIRED);
        leaseAgreementService.update(leaseAgreementLambdaUpdateWrapper);
    }
}


